package cn.ffcs.uec.staff.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cn.ffcs.uec.staff.dao.UecTalentTeamDao;
import cn.ffcs.uec.staff.model.UecTalentTeam;
import cn.ffcs.uec.staff.model.UecTitle;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.dao.BaseDaoImpl;
import cn.ffcs.uom.common.util.StrUtil;
import cn.ffcs.uom.common.vo.PageInfo;

@Repository("uecTalentTeamDao")
@Transactional
public class UecTalentTeamDaoImpl extends BaseDaoImpl
		implements UecTalentTeamDao {

	@Override
	public PageInfo queryPageInfoByUecTalentTeam(UecTalentTeam uecTalentTeam,
			int current, int pageSize) {
		if (null != uecTalentTeam) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_TALENT_TEAM T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			sb.append(" AND T.STATUS_CD = ? ");
			params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);

			//判断这个对象是外包人员的数据还是合同制的数据
			if (BaseUnitConstants.NM_OUT_STAFF_TYPE.equals(uecTalentTeam.getNmStaffType())) {
				sb.append(" AND T.NM_STAFF_TYPE = ? ");
				params.add(BaseUnitConstants.NM_OUT_STAFF_TYPE);
			}
			
			if (null != uecTalentTeam.getStaffId()) {
				sb.append(" AND T.STAFF_ID = ? ");
				params.add(uecTalentTeam.getStaffId());
			}else if(null != uecTalentTeam.getPkPsndoc()){
				sb.append(" AND T.PK_PSNDOC = ?");
				params.add(uecTalentTeam.getPkPsndoc());
			}
			return this.jdbcFindPageInfo(sb.toString(), params, current,
					pageSize, UecTalentTeam.class);
		}
		return null;
	}

	@Override
	public UecTalentTeam findUecTalentTeamById(UecTalentTeam uecTalentTeam) {
		if (null != uecTalentTeam) {
			StringBuilder sb = new StringBuilder(
					" SELECT * FROM UEC_TALENT_TEAM T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
			if (null != uecTalentTeam.getTalentTeamId()) {
				sb.append(" AND T.TALENT_TEAM_ID = ? ");
				params.add(uecTalentTeam.getTalentTeamId());
			}
			List<UecTalentTeam> talentTeams = this.jdbcFindList(sb.toString(), params, UecTalentTeam.class);
			if (null != talentTeams && talentTeams.size() > 0) {
				return talentTeams.get(0);
			}else {
				return null;
			}
		}
		return uecTalentTeam;
	}

	@Override
	public List<UecTalentTeam> getUecTalentTeamListByPkpsndoc(StaffAndOutStaff uecOutStaffInfo) {
		if (uecOutStaffInfo != null) {
			StringBuilder sb = new StringBuilder(" SELECT * FROM UEC_TALENT_TEAM T WHERE 1 = 1 ");
			List<Object> params = new ArrayList<Object>();
				sb.append(" AND T.STATUS_CD = ? ");
				params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
				if (!StrUtil.isNullOrEmpty(uecOutStaffInfo.getPkPsndoc())) {
					sb.append(" AND T.PK_PSNDOC = ? ");
					params.add(uecOutStaffInfo.getPkPsndoc());
				}
				sb.append(" ORDER BY T.GLBDEF4 ");
			List<UecTalentTeam> list = this.jdbcFindList(sb.toString(), params, UecTalentTeam.class);

			if (list.size() > 0) {
				return list;
			}
		}
		return null;
	}
}
